<template>
	<view class="sender-login-page">
		<image class="home" src="@/static/images/common/index-forward-icon.png" @click="onGoHome"></image>
		<view class="title">配送员登录</view>
		<form @submit="onSubmit">
			<view class="uni-form-item uni-column">
				<view class="input-label">账号</view>
				<view class="input-con">
					<input class="uni-input" focus name="userName"   placeholder="请输入账号" />
				</view>
			</view>
			<view class="uni-form-item uni-column">
				<view class="input-label">密码</view>
				<view class="input-con c-flex c-flex-row c-item-center">
					<input class="uni-input" password="true" name="password"  placeholder="请输入密码" />
				</view>
			</view>
			<button class="submit-bt" form-type="submit">登录</button>
		</form>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				
			};
		},
		methods:{
			...mapMutations(['setRole']),
			onGoHome(){
				uni.navigateBack({delta:1});
			},
			onSubmit(e){
				const name = e.detail.value.userName;
				const pwd = e.detail.value.password;
				if(name == '' ||  pwd == ''){
					return;
				}
				uni.showLoading({title:'加载中...'});
				this.$API.login({'username': name,'password': pwd,appCode:'energy',userType:2}).then(res =>{
					uni.hideLoading();
					// 记录token
					wx.setStorageSync('token', res.token);
					// wx.setStorageSync('tenants', JSON.stringify(res.tenants));
					// if(res.hasOwnProperty('tenants') && res.tenants.length>0){
					//   wx.setStorageSync('tenantId', res.tenants[0].id)
					// }
					this.setRole('delivery');
					uni.setStorageSync('type', 'delivery')
					uni.redirectTo({
						url:'../plat-menu/delivery'
					})
				});
			}
		}
	}
</script>
<style>page{background-color: white;}</style>
<style lang="scss" scoped>
.sender-login-page{
	font-family: PingFangSC, PingFang SC;position:relative;padding:0 58rpx;
	.title{font-weight: 600;font-size: 56rpx;color: #1F1E1E;margin:216rpx 0 56rpx 0;}
	.input-label{font-weight: 600;font-size: 32rpx;color: #1F1E1E;margin-bottom:48rpx;}
	.uni-form-item{margin-bottom:78rpx;}
	.input-con{
		position: relative;
		height: 98rpx;margin-top: 56rpx;background: #F7F8FA;border-radius: 16rpx;padding: 0 40rpx;
		input{height: 98rpx;flex:1;}
	}
	.submit-bt{
		width: 608rpx;height: 92rpx;line-height: 92rpx;
		background: linear-gradient( 180deg, #F18858 0%, #E86547 100%);	border-radius: 46rpx;
		font-size: 30rpx;font-weight: bold;color: #FFFFFF;margin-top: 86rpx; margin-left: 0;border: 1rpx solid #FFFFFF;
	}
	.home{width: 39rpx;height: 32rpx;;position: absolute;top: -72rpx;left: 52rpx;}
}
</style>
